package com.wzu.controller;

import com.wzu.entity.MedicalCard;
import com.wzu.entity.Result;
import com.wzu.service.MedicalCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/medicalCard")
@CrossOrigin
public class MedicalCardController {
    @Autowired
    private MedicalCardService medicalCardService;

    // 多条件查询
    @GetMapping("/list")
    public Result list(@RequestParam(required = false) String ruralCardNo,
                      @RequestParam(required = false) String cardId,
                      @RequestParam(required = false) String diseaseName) {
        List<MedicalCard> list = medicalCardService.searchMedicalCard(ruralCardNo, cardId, diseaseName);
        return new Result("查询成功", list, 200);
    }

    // 添加
    @PostMapping("/add")
    public Result add(@RequestBody MedicalCard medicalCard) {
        if (medicalCardService.addMedicalCard(medicalCard)) {
            return new Result("添加成功", null, 200);
        } else {
            return new Result("添加失败", null, 400);
        }
    }

    // 更新
    @PutMapping("/update")
    public Result update(@RequestBody MedicalCard medicalCard) {
        if (medicalCardService.updateMedicalCard(medicalCard)) {
            return new Result("更新成功", null, 200);
        } else {
            return new Result("更新失败", null, 400);
        }
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        if (medicalCardService.deleteMedicalCard(id)) {
            return new Result("删除成功", null, 200);
        } else {
            return new Result("删除失败", null, 400);
        }
    }
} 